home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-s-cm.cc < prev    next >
C/C++ Source or Header  |  1997-01-24  |  7KB  |  249 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-scalar.h"
  34. #include "ov-cx-mat.h"
  35. #include "ov-typeinfo.h"
  36. #include "op-s-cm.h"
  37. #include "ops.h"
  38. #include "xdiv.h"
  39. #include "xpow.h"
  40.  
  41. // scalar by complex matrix ops.
  42.  
  43. static octave_value
  44. add (const octave_value& a1, const octave_value& a2)
  45. {
  46.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  47.  
  48.   return octave_value (v1.double_value () + v2.complex_matrix_value ());
  49. }
  50.  
  51. static octave_value
  52. sub (const octave_value& a1, const octave_value& a2)
  53. {
  54.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  55.  
  56.   return octave_value (v1.double_value () - v2.complex_matrix_value ());
  57. }
  58.  
  59. static octave_value
  60. mul (const octave_value& a1, const octave_value& a2)
  61. {
  62.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  63.  
  64.   return octave_value (v1.double_value () * v2.complex_matrix_value ());
  65. }
  66.  
  67. static octave_value
  68. div (const octave_value&, const octave_value& v2)
  69. {
  70.   gripe_nonconformant ("operator /", 1, 1, v2.rows (), v2.columns ());
  71.   return octave_value ();
  72. }
  73.  
  74. static octave_value
  75. pow (const octave_value& a1, const octave_value& a2)
  76. {
  77.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  78.  
  79.   return xpow (v1.double_value (), v2.complex_matrix_value ());
  80. }
  81.  
  82. static octave_value
  83. ldiv (const octave_value& a1, const octave_value& a2)
  84. {
  85.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  86.  
  87.   double d = v1.double_value ();
  88.  
  89.   if (d == 0.0)
  90.     gripe_divide_by_zero ();
  91.  
  92.   return octave_value (v2.complex_matrix_value () / d);
  93. }
  94.  
  95. #define BOOL_OP(OP, EMPTY_RESULT) \
  96.   SC_MX_BOOL_OP (double, s, v1.double_value (), \
  97.          ComplexMatrix, m, v2.complex_matrix_value (), \
  98.          s OP real (m (i, j)), EMPTY_RESULT)
  99.  
  100. static octave_value
  101. lt (const octave_value& a1, const octave_value& a2)
  102. {
  103.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  104.  
  105.   BOOL_OP (<, Matrix ());
  106. }
  107.  
  108. static octave_value
  109. le (const octave_value& a1, const octave_value& a2)
  110. {
  111.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  112.  
  113.   BOOL_OP (<=, Matrix ());
  114. }
  115.  
  116. static octave_value
  117. eq (const octave_value& a1, const octave_value& a2)
  118. {
  119.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  120.  
  121.   SC_MX_BOOL_OP (double, s, v1.double_value (),
  122.          ComplexMatrix, m, v2.complex_matrix_value (),
  123.          s == m (i, j), 0.0);
  124. }
  125.  
  126. static octave_value
  127. ge (const octave_value& a1, const octave_value& a2)
  128. {
  129.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  130.  
  131.   BOOL_OP (>=, Matrix ());
  132. }
  133.  
  134. static octave_value
  135. gt (const octave_value& a1, const octave_value& a2)
  136. {
  137.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  138.  
  139.   BOOL_OP (>, Matrix ());
  140. }
  141.  
  142. static octave_value
  143. ne (const octave_value& a1, const octave_value& a2)
  144. {
  145.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  146.  
  147.   SC_MX_BOOL_OP (double, s, v1.double_value (),
  148.          ComplexMatrix, m, v2.complex_matrix_value (),
  149.          s != m (i, j), 1.0);
  150. }
  151.  
  152. static octave_value
  153. el_mul (const octave_value& a1, const octave_value& a2)
  154. {
  155.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  156.  
  157.   return octave_value (v1.double_value () * v2.complex_matrix_value ());
  158. }
  159.  
  160. static octave_value
  161. el_div (const octave_value& a1, const octave_value& a2)
  162. {
  163.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  164.  
  165.   return x_el_div (v1.double_value (), v2.complex_matrix_value ());
  166. }
  167.  
  168. static octave_value
  169. el_pow (const octave_value& a1, const octave_value& a2)
  170. {
  171.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  172.  
  173.   return elem_xpow (v1.double_value (), v2.complex_matrix_value ());
  174. }
  175.  
  176. static octave_value
  177. el_ldiv (const octave_value& a1, const octave_value& a2)
  178. {
  179.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  180.  
  181.   double d = v1.double_value ();
  182.  
  183.   if (d == 0.0)
  184.     gripe_divide_by_zero ();
  185.  
  186.   return octave_value (v2.complex_matrix_value () / d);
  187. }
  188.  
  189. static octave_value
  190. el_and (const octave_value& a1, const octave_value& a2)
  191. {
  192.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  193.  
  194.   SC_MX_BOOL_OP (double, s, v1.double_value (),
  195.          ComplexMatrix, m, v2.complex_matrix_value (),
  196.          s && m (i, j) != 0.0, Matrix ());
  197. }
  198.  
  199. static octave_value
  200. el_or (const octave_value& a1, const octave_value& a2)
  201. {
  202.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&);
  203.  
  204.   SC_MX_BOOL_OP (double, s, v1.double_value (),
  205.          ComplexMatrix, m, v2.complex_matrix_value (),
  206.          s || m (i, j) != 0.0, Matrix ());
  207. }
  208.  
  209. static octave_value *
  210. complex_matrix_conv (const octave_value& a)
  211. {
  212.   CAST_CONV_ARG (const octave_scalar&);
  213.  
  214.   return new octave_complex_matrix (v.complex_matrix_value ());
  215. }
  216.  
  217. void
  218. install_s_cm_ops (void)
  219. {
  220.   INSTALL_BINOP (add, octave_scalar, octave_complex_matrix, add);
  221.   INSTALL_BINOP (sub, octave_scalar, octave_complex_matrix, sub);
  222.   INSTALL_BINOP (mul, octave_scalar, octave_complex_matrix, mul);
  223.   INSTALL_BINOP (div, octave_scalar, octave_complex_matrix, div);
  224.   INSTALL_BINOP (pow, octave_scalar, octave_complex_matrix, pow);
  225.   INSTALL_BINOP (ldiv, octave_scalar, octave_complex_matrix, ldiv);
  226.   INSTALL_BINOP (lt, octave_scalar, octave_complex_matrix, lt);
  227.   INSTALL_BINOP (le, octave_scalar, octave_complex_matrix, le);
  228.   INSTALL_BINOP (eq, octave_scalar, octave_complex_matrix, eq);
  229.   INSTALL_BINOP (ge, octave_scalar, octave_complex_matrix, ge);
  230.   INSTALL_BINOP (gt, octave_scalar, octave_complex_matrix, gt);
  231.   INSTALL_BINOP (ne, octave_scalar, octave_complex_matrix, ne);
  232.   INSTALL_BINOP (el_mul, octave_scalar, octave_complex_matrix, el_mul);
  233.   INSTALL_BINOP (el_div, octave_scalar, octave_complex_matrix, el_div);
  234.   INSTALL_BINOP (el_pow, octave_scalar, octave_complex_matrix, el_pow);
  235.   INSTALL_BINOP (el_ldiv, octave_scalar, octave_complex_matrix, el_ldiv);
  236.   INSTALL_BINOP (el_and, octave_scalar, octave_complex_matrix, el_and);
  237.   INSTALL_BINOP (el_or, octave_scalar, octave_complex_matrix, el_or);
  238.  
  239.   INSTALL_ASSIGNCONV (octave_scalar, octave_complex_matrix, octave_complex_matrix);
  240.  
  241.   INSTALL_WIDENOP (octave_scalar, octave_complex_matrix, complex_matrix_conv);
  242. }
  243.  
  244. /*
  245. ;;; Local Variables: ***
  246. ;;; mode: C++ ***
  247. ;;; End: ***
  248. */
  249.